package com.smartcode.ai.service.impl;


import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.smartcode.ai.entity.po.StudentLearningRecord;
import com.smartcode.ai.mapper.StudentLearningRecordMapper;
import com.smartcode.ai.service.IStudentLearningRecordService;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class StudentLearningRecordServiceImpl extends ServiceImpl<StudentLearningRecordMapper, StudentLearningRecord> implements IStudentLearningRecordService {

    @Override
    public List<StudentLearningRecord> listByStudentAndCourse(String studentName, String courseName) {
        return lambdaQuery()
                .eq(StudentLearningRecord::getStudentName, studentName)
                .eq(StudentLearningRecord::getCourseName, courseName)
                .orderByDesc(StudentLearningRecord::getStudyTime)
                .list();
    }

    // 保存学习记录
    public String saveLearningRecord(String studentName, String courseName, Integer kpId, Integer masteryLevel, String notes) {
        StudentLearningRecord record = new StudentLearningRecord()
                .setStudentName(studentName)
                .setCourseName(courseName)
                .setKnowledgePointId(kpId)
                .setMasteryLevel(masteryLevel)
                .setNotes(notes)
                .setStudyTime(LocalDateTime.now());

        save(record);
        return "学习记录已保存，ID: " + record.getId();
    }
}